package adapter;

/**
 * @ClassName WithAdapterPatternDemo
 * @Description 适配器模式
 * @Author leejiliang
 * @DateTime 2021/2/23 17:47
 * @Version 1.0
 */
public class WithAdapterPatternDemo {
	public static void main(String[] args) {
		final NewInterFaceAdapter newInterFaceAdapter = new NewInterFaceAdapter(new OldImpl());
		final NewImpl aNew = new NewImpl();

		newInterFaceAdapter.newExecute();
		aNew.newExecute();
	}

	static class NewInterFaceAdapter implements NewInterface{

		private OldInterface oldInterface;

		public NewInterFaceAdapter(OldInterface oldInterface) {
			this.oldInterface = oldInterface;
		}

		@Override
		public void newExecute() {
			oldInterface.oldExecute();
		}
	}


	interface OldInterface{
		void oldExecute();
	}

	static class OldImpl implements OldInterface {

		@Override
		public void oldExecute() {
			System.out.println("old 处理逻辑");
		}
	}

	interface NewInterface{
		void newExecute();
	}

	static class NewImpl implements NewInterface {

		@Override
		public void newExecute() {
			System.out.println("new 处理逻辑");
		}
	}

}


